package corej.prj.commandlinebank.model;

import corej.prj.commandlinebank.exception.BalanceNotEnoughException;

public abstract class Account {

    private static long sid = 100000L;

    private long id;

    private String password;

    private String name;

    private String personId;

    private String email;

    private double balance;

    public Account() {
    }

    public Account(String password, String name, String personId, String email) {
        super();
        this.id = this.getNextId();
        this.password = password;
        this.name = name;
        this.personId = personId;
        this.email = email;
    }

    /*
      * �����һ��ɷ����id
      */
    private long getNextId() {
        return ++sid;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPersonId() {
        return personId;
    }

    public void setPersonId(String personId) {
        this.personId = personId;
    }

    public final void deposit(double money) {
        this.balance += money;
    }

    public abstract void withdraw(double money)
            throws BalanceNotEnoughException;

    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null)
            return false;
        if (this.getClass() != o.getClass())
            return false;
        Account c = (Account) o;
        if (this.id == c.id && this.password.equals(c.password)
                && this.name.equals(c.name) && this.personId.equals(c.personId)
                && this.email.equals(c.email) && this.balance == c.balance)
            return true;
        else
            return false;
    }
}
